package com.twu.bm.football;

import org.junit.Test;

import java.io.PrintStream;

import static org.hamcrest.core.AllOf.allOf;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class PlayerTest {

    PrintStream printStream = mock(PrintStream.class);

    String playerName = "John Smith";
    int playerAge = 30;
    String teamName = "Bengals";
    int number = 13;
    Player player = new Player(playerName, playerAge, teamName, number);
    String info = player.info();

    @Test
    public void playerInfoShouldIncludeAllPlayerAttributes() {
        assertThat(info, allOf(
                containsString(playerName),
                containsString(teamName),
                containsString("" + number),
                containsString("" + playerAge)
        ));
    }

    @Test
    public void infoShouldHaveASpace() {
        assertThat(info, containsString(" "));
    }

    @Test
    public void shouldPrintAllPlayerAttributesWhenPrinted() {
        player.print(printStream);
        verify(printStream).println(playerName);
        verify(printStream).println(playerAge);
        verify(printStream).println(teamName);
        verify(printStream).println(number);
    }

    @Test
    public void checkMatchesShouldReturnFalseWhenNameAndNumberInputsDontMatch() {
        assertThat(player.checkMatches(playerName, "15"), is(false));
    }

    @Test
    public void checkMatchesShouldReturnTrueWhenNameAndNumberInputsMatch() {
        assertThat(player.checkMatches(playerName, ""+ number), is(true));
    }

    @Test
    public void checkMatchesShouldReturnFalseWhenInputToCheckMatchesIsNotANumber() {
        assertThat(player.checkMatches(playerName, "notANumber"), is(false));
    }
}
